<?php
/**
 * Created by PhpStorm.
 * User: ulinix
 * Date: 2017/10/12
 * Time: 18:53
 */
namespace Home\Controller;
use Admin\Controller\CheckController;

class TestController  extends CheckController
{
 
    public function test()              
    {
        header("Content-Type: text/html; charset=UTF-8");
        //导入phpQuery
        import('Org.JAE.QueryList');                                     
        $user=M("article");
        if($_GET['p']<=20&&$_GET['p']) {
            $id = $_GET['p'];
            //要采集的网站地址
            switch ($id){
                case 1:$url_host="http://uy.ts.cn/turmush/saghlamliq/"; $pid=245;$th_url="sahlamlih";$from_url="http://uy.ts.cn/turmush/saghlamliq/";$turname="ساغلاملىق";break;//ساغلاملىق
                case 2:$url_host="http://uy.ts.cn/turmush/aele/"; $pid=225;$th_url="nikah";$from_url="http://uy.ts.cn/turmush/aele/index.shtml";$turname="ئائىلە ۋە نىكاھ";break;  //ئائىلە ۋە نىكاھ
                case 3:$url_host="http://uy.ts.cn/turmush/qizlar/"; $pid=247;$th_url="hk";$from_url="http://uy.ts.cn/turmush/qizlar/index.shtml";$turname="خانىم قىزلار";break;   //خانىم قىزلار
                case 4:$url_host="http://uy.ts.cn/turmush/turmush_lughut/"; $pid=223;$th_url="sahlamlih";$from_url="http://uy.ts.cn/turmush/turmush_lughut/index.shtml";$turname="تۇمۇش لۇغىتى";break; //تۇمۇش لۇغىتى
                case 5:$url_host="http://uy.ts.cn/turmush/balilar/index.shtml"; $pid=450;$th_url="balilar";$from_url="http://uy.ts.cn/turmush/balilar/index.shtml";$turname="بالىلار ساغلاملىقى";break; // بالىلار ساغلاملىقى
                case 6:$url_host="http://uy.ts.cn/turmush/ehleq/index.shtml"; $pid=224;$th_url="at";$from_url="http://uy.ts.cn/turmush/ehleq/index.shtml";$turname="ئەخلاق تەربىيە";break; // ئەخلاق تەربىيە
                case 7:$url_host="http://uy.ts.cn/hewer/bilim/index.shtml";$pid=233;$from_url="http://uy.ts.cn/hewer/bilim/index.shtml";$turname="بىلىم يۇرتى";break; // بىلىم يۇرتى
                default:echo "<div style='font-family:ALKATIP Basma Tom;direction: rtl;text-align: center;background-color: #f5f5f5;padding: 15px;color: red'>ماس بولغان نۇمۇرنى يېزىڭ~!</div>";die;break;
            }
            $wher=array("title"=>'');
            $user->where($wher)->delete();
            \phpQuery::newDocumentFile($url_host);
            $artlist = pq(".articles li");
            for ($i=0;$i<=count($artlist);$i++){
                if($id==7){
                    $th=array("pt","pt1","pt2","pt3","pt4") ;
                    $th_url=$th[rand(0,4)];
                }
                $title= pq($artlist)->eq($i)->find(".article-title")->text();
                $row= $user->where("title='$title'")->field('title')->find();
                if($row){
                    $tt=$row['title'];
                    echo "<div style='font-family:ALKATIP Basma Tom;direction: rtl;text-align: center;background-color: #f5f5f5;padding: 15px'>بۇ تېما كىرگۈزۈپ بولۇنغان :<span style='color: red'> [ $tt ] </span> >>>>>>>>> <span style='color: red'> [ $turname ] </span>سەھىپىسىنى <span>采集</span>قىلىش تاماملاندى !</div>";
                    die;
                }
                $url=  pq($artlist)->eq($i)->find("a")->attr("href") ;
                //获取文章的正文内容
                \phpQuery::newDocumentFile($url);
                $content1=pq(".article-content")->html();
                $intime=time();
                //获取文章的封面图片
                $thumb=pq('.article-content')->find("img")->eq(0)->attr("src");
                $thumb=$thumb?$thumb:"/Application/Home/static/img/".$th_url.".jpg";
                //发布者
                $author="ياخشىمۇسىز";
                $from_source=24; //مەنبەسى
                $time=time();
                $data=array(
                    'pid'=>$pid,'title'=>$title,'sort'=>0,'summer'=>'','content'=>'','content1'=>$content1,'status'=>1,'author'=>$author
                ,'from_url'=>$from_url,'from_source'=>$from_source,'from_face'=>'','standby1'=>'','standby2'=>''
                ,'thumb'=>$thumb,'bgcolor'=>'','color'=>'','intime'=>$intime,'uptime'=>$time,'click'=>0,'search'=>1,'favour'=>0
                );
                //添加到数据库
                $user->add($data);
            }
//            $id--;
//            $id=$id<10?'0'.$id:$id;
//            p("正在采集URL数据列表$id...请稍后...");
//            echo "<script>window.location='http://www.yahximusiz.com/index.php/Home/Test/test?p=$id'</script>";
        }else {
            echo "<div style='font-family:ALKATIP Basma Tom;direction: rtl;text-align: center;background-color: #f5f5f5;padding: 15px'>采集قىلىش تاماملاندى !</div>";die;
        }









//        $user=M('article');
        //采集OSC的代码分享列表，标题 链接 作者
//        $where=array("title"=>"");
//        $user->where($where)->delete();
//        static $pid=309;
//        if($_GET['p']<=10&&$_GET['p']) {
//            $id = $_GET['p'];
//            //要采集的网站地址
//            $url_host='https://www.anabala.com/Posts/TableContent?Month='.$id;
//            \phpQuery::newDocumentFile($url_host);
//            //父级id
//            $pid=$pid+$id-1;                //***************************************
//            $title= pq('.h3-cats')->text();
//            pq('.h3-cats')->remove();
//            $content1= pq(".cats2")->html();
//            $content1.= pq(".content")->html();
//            //获取文章的封面图片  获取文章的图片，如果没有图片就自动替换文件夹的图片
//            $thumb='/Application/Home/static/img/bg5-big.jpg' ;
//            $intime=time();
//            //发布者
//            $author="ياخشىمۇسىز";
//            $from_url="https://www.anabala.com"; //مەنبە ئادرىسى
//            $from_source=33; //مەنبەسى
//            $time=time();
//            $data=array(
//                'pid'=>$pid,'title'=>$title,'sort'=>0,'summer'=>'','content'=>'','content1'=>$content1,'status'=>1,'author'=>$author
//            ,'from_url'=>$from_url,'from_source'=>$from_source,'from_face'=>'','standby1'=>'','standby2'=>''
//            ,'thumb'=>$thumb,'bgcolor'=>'','color'=>'','intime'=>$intime,'uptime'=>$time,'click'=>0,'search'=>1,'favour'=>0
//            );
////                添加到数据库
//            $user->add($data);
//            $id++;
//            $id=$id<10?'0'.$id:$id;
//            p("正在采集URL数据列表$id...请稍后...");
//            echo "<script>window.location='http://www.yahximusiz.com/index.php/Home/Test/test?p=$id'</script>";
//        }else {
//            p("采集数据结束");
//        }












//        if($_GET['p']<=5&&$_GET['p']) {    //***************************************
//            $id = $_GET['p'];
//            $catid=22;                   //***************************************
//            //要采集的网站地址
//            $url_host='https://www.anabala.com/Posts/List/'.$catid.'/'.$id.'?catId='.$catid;
//            \phpQuery::newDocumentFile($url_host);
//            $artlist = pq(".lists li");
//            for ($i=0;$i<=count($artlist);$i++){
//                //父级id
//                $pid=326;                //***************************************
//                $title= pq($artlist)->eq($i)->find(".title")->text();
//                //获取文章的封面图片  获取文章的图片，如果没有图片就自动替换文件夹的图片
//                $thumb=pq($artlist)->eq($i)->find("img")->attr("src");
//                $thumb=$thumb?"https://www.anabala.com".$thumb:"/Application/Home/static/img/hamila.jpg";
//                $url="https://www.anabala.com".pq($artlist)->eq($i)->find("a")->attr("href");
//                //获取文章的正文内容
//                \phpQuery::newDocumentFile($url);
//                pq("script,.icon-views,.title")->remove();
//                $content1=pq(".content")->text();
//                $src="https://www.anabala.com".pq(".content img")->attr('src');
//                $content1.=pq(".content img")->attr('src')?"<img src='$src'>":"";
//                $intime=time();
//                //发布者
//                $author="ياخشىمۇسىز";
//                $from_url="https://www.anabala.com"; //مەنبە ئادرىسى
//                $from_source=33; //مەنبەسى
//                $time=time();
//                $data=array(
//                    'pid'=>$pid,'title'=>$title,'sort'=>0,'summer'=>'','content'=>'','content1'=>$content1,'status'=>1,'author'=>$author
//                ,'from_url'=>$from_url,'from_source'=>$from_source,'from_face'=>'','standby1'=>'','standby2'=>''
//                ,'thumb'=>$thumb,'bgcolor'=>'','color'=>'','intime'=>$intime,'uptime'=>$time,'click'=>0,'search'=>1,'favour'=>0
//                );
////                添加到数据库
//                $user->add($data);
//            }
//            $id++;
//            $id=$id<10?'0'.$id:$id;
//            p("正在采集URL数据列表$id...请稍后...");
//            echo "<script>window.location='http://www.yahximusiz.com/index.php/Home/Test/test?p=$id'</script>";
//        }else {
//            p("采集数据结束");
//        }

    }
}